#include <iostream>
#include <vector>
#include <list>
using namespace std;
int main()
{
    int num1, num2, val;
    list<int> l;
    vector<int> findRes;
    while (cin >> num1 >> num2)
    {
        if (num1 == 1)
        {
            // insert
            cin >> val;
            if (num2 == 0)
            {
                l.push_front(val); //头插
            }
            else
            {
                //指定位置插入
                list<int>::iterator listIt = l.begin();
                for (int i = 0; i < num2; i++)
                {
                    listIt++;
                }
                l.insert(listIt, val);
            }
        }
        else
        {
            list<int>::iterator it = l.begin();
            for (int i = 0; i < num2; i++)
            {
                it++;
            }
            if (num1 == 2) // del
            {
                if (it != l.end())
                {
                    l.erase(it);
                }
            }
            else
            {
                // find
                if (it != l.end())
                {
                    findRes.push_back(*it);
                }
                else
                {
                    findRes.push_back(-1);
                }
            }
        }
    }
    for (auto &e : findRes)
    {
        cout << e << endl;
    }
    return 0;
}